package com.iracing.telemetry.facade;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import com.iracing.telemetry.dao.TelemetryDAO;
import com.iracing.telemetry.data.TelemetrySessionData;
import com.iracing.telemetry.data.result.ResultTelemetryFilesData;
import com.iracing.telemetry.data.result.ResultTelemetrySessionData;
import com.iracing.telemetry.data.result.ResultTelemetrySessionData.Code;
import com.iracing.telemetry.exception.TelemetryException;

public class TelemetryFacade implements ITelemetryFacade {

	private TelemetryDAO telemetryDAO;

	public TelemetryFacade() {
		telemetryDAO = new TelemetryDAO();
	}

	@Override
	public ResultTelemetrySessionData provideTelemetryData(String telemetryFileName) {

		ResultTelemetrySessionData result = new ResultTelemetrySessionData();

		try {
			result.setCode(Code.NO_OK);
			TelemetrySessionData data = telemetryDAO
					.parseTelemetryFile(telemetryFileName);
			if (data != null) {
				result.setCode(Code.OK);
				result.setData(data);
			}
		} catch (TelemetryException e) {
			if (e.getCause() instanceof FileNotFoundException) {
				result.setCode(Code.FILE_NOT_FOUND);
			} else if (e.getCause() instanceof IOException) {
				result.setCode(Code.ERROR_PARSING_FILE);
			}
		}

		return result;

	}

	@Override
	public void getTelemetryParamData(String telemetryFileName,
			String telemetryParamName) {
		// TODO Auto-generated method stub

	}

	@Override
	public ResultTelemetryFilesData getTelemetryFiles(String access,
			String car, String track) {
		
		List<String> list = new ArrayList<String>();
		
		
		
		return null;

	}
}
